home *** CD-ROM | disk | FTP | other *** search
/ MacWorld: Conference & Expo 2005 / Macworld Conference and Expo - Documentation CD-ROM (2004).iso / mac / Adobe Reader 6.0 / Adobe Reader 6.0.app / Contents / MacOS / cos2xfdf.xml < prev    next >
Extensible Markup Language  |  2004-01-30  |  24KB  |  782 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!-- preprocess -->
  3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://ns.adobe.com/xfdf/">
  4. <xsl:output method="xml" encoding="UTF-8" indent="no" omit-xml-declaration="no"/>
  5.  
  6.     <xsl:variable name="HexArray">0123456789ABCDEF</xsl:variable>
  7.  
  8.     <!--    Convert color value from a floating number between
  9.             zero and one to a hexadecimal value between 00 and FF -->
  10.     <xsl:template name="convertColor">
  11.         <xsl:param name="Color"/>
  12.         <xsl:variable name="ColorAsInt"><xsl:value-of select="number($Color)"/></xsl:variable>
  13.         <xsl:choose>
  14.             <xsl:when test="$ColorAsInt = 0">
  15.                 <xsl:text>00</xsl:text>
  16.             </xsl:when>
  17.             <xsl:when test="$ColorAsInt = 1">
  18.                 <xsl:text>FF</xsl:text>
  19.             </xsl:when>
  20.             <xsl:otherwise>
  21.                 <xsl:variable name="RangedColor"><xsl:value-of select="round($ColorAsInt * 255)"/></xsl:variable>
  22.                 <xsl:variable name="MSDigit"><xsl:value-of select="floor($RangedColor div 16)"/></xsl:variable>
  23.                 <xsl:variable name="LSDigit"><xsl:value-of select="$RangedColor mod 16"/></xsl:variable>
  24.                 <xsl:value-of select="substring ($HexArray, $MSDigit + 1, 1)"/><xsl:value-of select="substring ($HexArray, $LSDigit + 1, 1)"/>
  25.             </xsl:otherwise>
  26.         </xsl:choose>
  27.     </xsl:template>
  28.  
  29.     <!--    Put out the parameters associated with a stream generic to
  30.             the annotation -->
  31.     <xsl:template name="emitParams">
  32.         <xsl:apply-templates select="../*[not(self::DICT[@KEY='Mac'] or self::DATA or self::NAME[@KEY='Filter'] or self::ARRAY[@KEY='Filter'] or self::INT[@KEY='Length'])]"/>
  33.     </xsl:template>
  34.  
  35.     <!--    Put out the stream parameters specific to
  36.             the data of the annotation -->
  37.     <xsl:template name="emitRestofParams">
  38.         <xsl:apply-templates select="../INT[@KEY='Length']|../../INT[@KEY='Subtype' or @KEY='Creator']"/>
  39.         <xsl:attribute name="filter">
  40.             <xsl:for-each select="../NAME[@KEY='Filter']/@VAL|../ARRAY[@KEY='Filter']/NAME/@VAL">
  41.                 <xsl:value-of select="."/>
  42.                 <xsl:if test="position() != last()">,</xsl:if>
  43.             </xsl:for-each>
  44.         </xsl:attribute>
  45.     </xsl:template>
  46.  
  47.     <xsl:template match="/">
  48.         <xsl:apply-templates/>
  49.     </xsl:template>
  50.           
  51.     <xsl:template match="APPEARANCE">
  52.         <xsl:element name="appearance">
  53.             <xsl:value-of select="."/>
  54.         </xsl:element>
  55.     </xsl:template>
  56.  
  57.     <xsl:template match="ARRAY[@KEY]">
  58.         <xsl:variable name="keyvalue"><xsl:value-of select="@KEY"/></xsl:variable>
  59.  
  60.         <xsl:choose>
  61.  
  62.             <!--    ID values (not annotations or fields, but should
  63.                     be round tripped, to facilitate finding a PDF) -->
  64.             <xsl:when test="$keyvalue = 'ID'">
  65.                 <xsl:element name="ids">
  66.                     <xsl:attribute name="original">
  67.                         <xsl:value-of select="STRING[1]"/>
  68.                     </xsl:attribute>
  69.                     <xsl:attribute name="modified">
  70.                         <xsl:value-of select="STRING[2]"/>
  71.                     </xsl:attribute>
  72.                 </xsl:element>
  73.             </xsl:when>
  74.  
  75.             <!-- Start of the annotations -->
  76.             <xsl:when test="$keyvalue = 'Annots'">
  77.                 <xsl:element name="annots">
  78.                     <xsl:apply-templates select="DICT[@DEFINE]"/>
  79.                 </xsl:element>
  80.             </xsl:when>
  81.  
  82.             <!-- Start of the fields -->
  83.             <xsl:when test="$keyvalue = 'Fields'">
  84.                 <xsl:element name="fields">
  85.                     <xsl:apply-templates select="DICT[not(@*)]"/>
  86.                 </xsl:element>
  87.             </xsl:when>
  88.  
  89.             <!-- Line coordinates -->
  90.             <xsl:when test="$keyvalue = 'L'">
  91.                 <xsl:attribute name="start">
  92.                     <xsl:value-of select="(FIXED|INT)[1]/@VAL"/>
  93.                     <xsl:text>,</xsl:text>
  94.                     <xsl:value-of select="(FIXED|INT)[2]/@VAL"/>
  95.                 </xsl:attribute>
  96.                 <xsl:attribute name="end">
  97.                     <xsl:value-of select="(FIXED|INT)[3]/@VAL"/>
  98.                     <xsl:text>,</xsl:text>
  99.                     <xsl:value-of select="(FIXED|INT)[4]/@VAL"/>
  100.                 </xsl:attribute>
  101.             </xsl:when>
  102.  
  103.             <!-- Line end style -->
  104.             <xsl:when test="$keyvalue = 'LE'">
  105.                 <xsl:attribute name="head">
  106.                     <xsl:value-of select="NAME[1]/@VAL"/>
  107.                 </xsl:attribute>
  108.                 <xsl:attribute name="tail">
  109.                     <xsl:value-of select="NAME[2]/@VAL"/>
  110.                 </xsl:attribute>
  111.             </xsl:when>
  112.  
  113.             <!-- Rectangle coordinates -->
  114.             <xsl:when test="$keyvalue = 'Rect'">
  115.                 <xsl:attribute name="rect">
  116.                     <xsl:for-each select="FIXED|INT">
  117.                         <xsl:value-of select="format-number(@VAL,'0.000000')"/><xsl:if test="position() != last()">,</xsl:if>
  118.                     </xsl:for-each>
  119.                 </xsl:attribute>
  120.             </xsl:when>
  121.  
  122.             <!-- Inline Text Rectangle coordinates -->
  123.             <xsl:when test="$keyvalue = 'InlineTextRect'">
  124.                 <xsl:attribute name="inlinetextrect">
  125.                     <xsl:for-each select="FIXED|INT">
  126.                         <xsl:value-of select="format-number(@VAL,'0.000000')"/><xsl:if test="position() != last()">,</xsl:if>
  127.                     </xsl:for-each>
  128.                 </xsl:attribute>
  129.             </xsl:when>
  130.  
  131.             <!-- Caret Rectangle coordinates -->
  132.             <xsl:when test="$keyvalue = 'CaretRect'">
  133.                 <xsl:attribute name="caretrect">
  134.                     <xsl:for-each select="FIXED|INT">
  135.                         <xsl:value-of select="format-number(@VAL,'0.000000')"/><xsl:if test="position() != last()">,</xsl:if>
  136.                     </xsl:for-each>
  137.                 </xsl:attribute>
  138.             </xsl:when>
  139.  
  140.             <!--    fringe rectangle (around circles and
  141.                     squares with cloud border effect) -->
  142.             <xsl:when test="$keyvalue = 'RD'">
  143.                 <xsl:attribute name="fringe">
  144.                     <xsl:for-each select="FIXED|INT">
  145.                         <xsl:value-of select="format-number(@VAL,'0.000000')"/><xsl:if test="position() != last()">,</xsl:if>
  146.                     </xsl:for-each>
  147.                 </xsl:attribute>
  148.             </xsl:when>
  149.  
  150.             <!-- inklist -->
  151.             <xsl:when test="$keyvalue = 'InkList'">
  152.                 <xsl:element name="inklist">
  153.                     <xsl:for-each select="ARRAY">
  154.                         <xsl:element name="gesture">
  155.                             <xsl:for-each select="FIXED|INT">
  156.                                 <xsl:value-of select="@VAL"/>
  157.                                 <xsl:choose>
  158.                                     <xsl:when test="position() = last()"/>
  159.                                     <xsl:when test="position() mod 2 = 1">,</xsl:when>
  160.                                     <xsl:otherwise>;</xsl:otherwise>
  161.                                 </xsl:choose>
  162.                             </xsl:for-each>
  163.                         </xsl:element>
  164.                     </xsl:for-each>
  165.                 </xsl:element>
  166.             </xsl:when>
  167.  
  168.             <!-- polygon vertices -->
  169.             <xsl:when test="$keyvalue = 'Vertices' or $keyvalue = 'vertices'">
  170.                 <xsl:element name="vertices">
  171.                     <xsl:for-each select="FIXED|INT">
  172.                         <xsl:value-of select="@VAL"/>
  173.                         <xsl:choose>
  174.                             <xsl:when test="position() = last()"/>
  175.                             <xsl:when test="position() mod 2 = 1">,</xsl:when>
  176.                             <xsl:otherwise>;</xsl:otherwise>
  177.                         </xsl:choose>
  178.                     </xsl:for-each>
  179.                 </xsl:element>
  180.             </xsl:when>
  181.  
  182.             <!-- Border Dashes -->
  183.             <xsl:when test="$keyvalue = 'D'">
  184.                 <xsl:variable name="Dashes">
  185.                     <xsl:for-each select="(FIXED|INT)/@VAL">
  186.                         <xsl:value-of select="."/><xsl:text>,</xsl:text>
  187.                     </xsl:for-each>
  188.                 </xsl:variable>
  189.                 <!-- trim off last comma -->
  190.                 <xsl:attribute name="dashes">
  191.                     <xsl:value-of select="substring($Dashes, 1, string-length($Dashes) - 1)"/>
  192.                 </xsl:attribute>
  193.             </xsl:when>
  194.  
  195.             <!-- Border -->
  196.             <xsl:when test="$keyvalue = 'Border'">
  197.                 <!--    only use the Border array if no
  198.                         border style settings are available -->
  199.                 <xsl:if test="not(../DICT[@KEY='BS'])">
  200.                     <xsl:variable name="DashesPresent" select="count(FIXED|INT) > 3"/>
  201.                     <xsl:attribute name="style">
  202.                         <xsl:choose>
  203.                             <xsl:when test="$DashesPresent">
  204.                                 <xsl:text>dash</xsl:text>
  205.                             </xsl:when>
  206.                             <xsl:otherwise>
  207.                                 <xsl:text>solid</xsl:text>
  208.                             </xsl:otherwise>
  209.                         </xsl:choose>
  210.                     </xsl:attribute>
  211.                     <xsl:attribute name="width">
  212.                         <xsl:value-of select="(FIXED|INT)[3]/@VAL"/>
  213.                     </xsl:attribute>
  214.                     <xsl:if test="$DashesPresent">
  215.                         <xsl:attribute name="dashes">
  216.                             <xsl:for-each select="(FIXED|INT)[position() > 3]">
  217.                                 <xsl:value-of select="@VAL"/>
  218.                                 <xsl:if test="position() != last()">
  219.                                     <xsl:text>,</xsl:text>
  220.                                 </xsl:if>
  221.                             </xsl:for-each>
  222.                         </xsl:attribute>
  223.                     </xsl:if>
  224.                 </xsl:if>
  225.             </xsl:when>
  226.  
  227.             <!-- Color -->
  228.             <xsl:when test="$keyvalue = 'C'">
  229.                 <xsl:attribute name="color">
  230.                     <xsl:text>#</xsl:text>
  231.                     <xsl:for-each select="FIXED|INT">
  232.                         <xsl:call-template name="convertColor">
  233.                             <xsl:with-param name="Color" select="@VAL"/>
  234.                         </xsl:call-template>
  235.                     </xsl:for-each>
  236.                 </xsl:attribute>
  237.             </xsl:when>
  238.  
  239.             <!-- Interior Color -->
  240.             <!--    trivial case: don't put out interior-color
  241.                     if there are no color values -->
  242.             <xsl:when test="$keyvalue = 'IC' and (FIXED|INT)">
  243.                 <xsl:attribute name="interior-color">
  244.                     <xsl:text>#</xsl:text>
  245.                     <xsl:for-each select="FIXED|INT">
  246.                         <xsl:call-template name="convertColor">
  247.                             <xsl:with-param name="Color" select="@VAL"/>
  248.                         </xsl:call-template>
  249.                     </xsl:for-each>
  250.                 </xsl:attribute>
  251.             </xsl:when>
  252.  
  253.             <!-- QuadPoints -->
  254.             <xsl:when test="$keyvalue = 'QuadPoints'">
  255.                 <xsl:attribute name="coords">
  256.                     <xsl:for-each select="FIXED|INT">
  257.                         <xsl:value-of select="@VAL"/>
  258.                         <xsl:if test="position() != last()">,</xsl:if>
  259.                     </xsl:for-each>
  260.                 </xsl:attribute>
  261.             </xsl:when>
  262.  
  263.         </xsl:choose>
  264.     </xsl:template>
  265.  
  266.     <xsl:template match="BOOL[@KEY = 'Open']">
  267.         <xsl:variable name="keyvalue"><xsl:value-of select="@KEY"/></xsl:variable>
  268.         <xsl:attribute name="open">
  269.             <xsl:choose>
  270.                 <xsl:when test="@VAL='true'">yes</xsl:when>
  271.                 <xsl:otherwise>no</xsl:otherwise>
  272.             </xsl:choose>
  273.         </xsl:attribute>
  274.     </xsl:template>
  275.  
  276.     <!--    rather than check the ancestor to see if we are handling
  277.             a field or an annot, just use a different mode for fields -->
  278.     <xsl:template match="STRING[@KEY = 'T']" mode="fields">
  279.         <xsl:element name="field">
  280.             <xsl:attribute name="name">
  281.                 <xsl:value-of select="text()"/>
  282.             </xsl:attribute>
  283.             <xsl:choose>
  284.                 <xsl:when test="../ARRAY[@KEY = 'Kids']">
  285.                     <xsl:apply-templates select="../ARRAY[@KEY = 'Kids']/DICT"/>
  286.                 </xsl:when>
  287.                 <xsl:when test="../ARRAY[@KEY = 'V']">
  288.                     <xsl:for-each select="../ARRAY[@KEY = 'V']/STRING">
  289.                         <xsl:element name="value">
  290.                             <xsl:value-of select="text()"/>
  291.                         </xsl:element>
  292.                     </xsl:for-each>
  293.                 </xsl:when>
  294.                 <!--    ordering here is significant: 
  295.                         when both <STRING KEY="V"> and
  296.                         <STRING KEY="RV"> are present, use
  297.                         <STRING KEY="RV"> -->
  298.                 <xsl:when test="../STRING[@KEY = 'RV']">
  299.                     <xsl:element name="value-richtext">
  300.                         <xsl:value-of select="../STRING[@KEY = 'RV']/text()"/>
  301.                     </xsl:element>
  302.                 </xsl:when>
  303.                 <xsl:when test="../STRING[@KEY = 'V']">
  304.                     <xsl:element name="value">
  305.                         <xsl:value-of select="../STRING[@KEY = 'V']/text()"/>
  306.                     </xsl:element>
  307.                 </xsl:when>
  308.                 <xsl:when test="../NAME[@KEY = 'V']">
  309.                     <xsl:element name="value">
  310.                         <xsl:value-of select="../NAME[@KEY = 'V']/@VAL"/>
  311.                     </xsl:element>
  312.                 </xsl:when>
  313.             </xsl:choose>
  314.         </xsl:element>
  315.     </xsl:template>
  316.  
  317.     <!-- get rid of any extraneous text nodes and attributes -->
  318.     <xsl:template match="text()|@*" mode="fields"/>
  319.  
  320.     <xsl:template match="STRING[@KEY]">
  321.         <xsl:variable name="keyvalue"><xsl:value-of select="@KEY"/></xsl:variable>
  322.         <xsl:choose>
  323.  
  324.             <!-- File href -->
  325.             <xsl:when test="$keyvalue = 'F'">
  326.                 <xsl:choose>
  327.                     <xsl:when test="../@KEY = 'FDF'">
  328.                         <xsl:element name="f">
  329.                             <xsl:attribute name="href">
  330.                                 <xsl:value-of select="text()"/>
  331.                             </xsl:attribute>
  332.                         </xsl:element>
  333.                     </xsl:when>
  334.                     <xsl:otherwise>
  335.                         <xsl:attribute name="file">
  336.                             <xsl:value-of select="text()"/>
  337.                         </xsl:attribute>
  338.                     </xsl:otherwise>
  339.                 </xsl:choose>
  340.             </xsl:when>
  341.  
  342.             <!-- start Stream Parameters -->
  343.  
  344.             <!-- Creation Date -->
  345.             <xsl:when test="$keyvalue = 'CreationDate'">
  346.                 <xsl:choose>
  347.                     <xsl:when test="ancestor::STREAM">
  348.                         <xsl:attribute name="creation">
  349.                             <xsl:value-of select="text()"/>
  350.                         </xsl:attribute>
  351.                     </xsl:when>
  352.                     <xsl:otherwise>
  353.                         <xsl:attribute name="creationdate">
  354.                             <xsl:value-of select="text()"/>
  355.                         </xsl:attribute>
  356.                     </xsl:otherwise>
  357.                 </xsl:choose>
  358.             </xsl:when>
  359.  
  360.             <!-- File Modification Date -->
  361.             <xsl:when test="$keyvalue = 'ModDate'">
  362.                 <xsl:choose>
  363.                     <xsl:when test="ancestor::STREAM">
  364.                         <xsl:attribute name="modification">
  365.                             <xsl:value-of select="text()"/>
  366.                         </xsl:attribute>
  367.                     </xsl:when>
  368.                     <xsl:otherwise>
  369.                         <xsl:attribute name="date">
  370.                             <xsl:value-of select="text()"/>
  371.                         </xsl:attribute>
  372.                     </xsl:otherwise>
  373.                 </xsl:choose>
  374.             </xsl:when>
  375.  
  376.             <!-- File Checksum -->
  377.             <xsl:when test="$keyvalue = 'CheckSum'">
  378.                 <xsl:attribute name="checksum">
  379.                     <xsl:value-of select="text()"/>
  380.                 </xsl:attribute>
  381.             </xsl:when>
  382.  
  383.             <!-- end STREAM PARAMS -->
  384.  
  385.             <!-- Name Identifier -->
  386.             <xsl:when test="$keyvalue = 'NM'">
  387.                 <xsl:attribute name="name">
  388.                     <xsl:value-of select="text()"/>
  389.                 </xsl:attribute>
  390.             </xsl:when>
  391.  
  392.             <!-- In reply to Identifier -->
  393.             <xsl:when test="$keyvalue = 'IRT'">
  394.                 <xsl:attribute name="inreplyto">
  395.                     <xsl:value-of select="text()"/>
  396.                 </xsl:attribute>
  397.             </xsl:when>
  398.  
  399.             <!-- Subject -->
  400.             <xsl:when test="$keyvalue = 'Subj'">
  401.                 <xsl:attribute name="subject">
  402.                     <xsl:value-of select="text()"/>
  403.                 </xsl:attribute>
  404.             </xsl:when>
  405.  
  406.             <!-- Title -->
  407.             <xsl:when test="$keyvalue = 'T'">
  408.                 <xsl:attribute name="title">
  409.                     <xsl:value-of select="text()"/>
  410.                 </xsl:attribute>
  411.             </xsl:when>
  412.  
  413.             <!-- Modification Date -->
  414.             <xsl:when test="$keyvalue = 'M'">
  415.                 <xsl:attribute name="date">
  416.                     <xsl:value-of select="text()"/>
  417.                 </xsl:attribute>
  418.             </xsl:when>
  419.  
  420.             <!-- Contents -->
  421.             <xsl:when test="$keyvalue = 'Contents'">
  422.                 <xsl:element name="contents">
  423.                     <xsl:value-of select="text()"/>
  424.                 </xsl:element>
  425.             </xsl:when>
  426.  
  427.             <!-- Rich Text Contents -->
  428.             <xsl:when test="$keyvalue = 'RC'">
  429.                 <xsl:element name="contents-richtext">
  430.                     <xsl:value-of select="text()"/>
  431.                 </xsl:element>
  432.             </xsl:when>
  433.  
  434.             <xsl:when test="$keyvalue = 'State'">
  435.                 <xsl:attribute name="state">
  436.                     <xsl:value-of select="text()"/>
  437.                 </xsl:attribute>
  438.             </xsl:when>
  439.  
  440.             <xsl:when test="$keyvalue = 'StateModel'">
  441.                 <xsl:attribute name="statemodel">
  442.                     <xsl:value-of select="text()"/>
  443.                 </xsl:attribute>
  444.             </xsl:when>
  445.  
  446.             <!-- Default appearance -->
  447.             <xsl:when test="$keyvalue = 'DA'">
  448.                 <xsl:element name="defaultappearance">
  449.                     <xsl:value-of select="text()"/>
  450.                 </xsl:element>
  451.             </xsl:when>
  452.  
  453.             <!-- Default style -->
  454.             <xsl:when test="$keyvalue = 'DS'">
  455.                 <xsl:element name="defaultstyle">
  456.                     <xsl:value-of select="text()"/>
  457.                 </xsl:element>
  458.             </xsl:when>
  459.  
  460.         </xsl:choose>
  461.     </xsl:template>
  462.  
  463.     <xsl:template match="INT[@KEY]">
  464.         <xsl:variable name="keyvalue"><xsl:value-of select="@KEY"/></xsl:variable>
  465.         <xsl:choose>
  466.  
  467.             <!-- Rotation -->
  468.             <xsl:when test="$keyvalue = 'Rotate'">
  469.                 <xsl:attribute name="rotation">
  470.                     <xsl:value-of select="@VAL"/>
  471.                 </xsl:attribute>
  472.             </xsl:when>
  473.  
  474.             <!-- Flags -->
  475.             <xsl:when test="$keyvalue = 'F'">
  476.                 <xsl:variable name="BitValue" select="number(@VAL)"/>
  477.                 <!-- test individual bits -->
  478.                 <xsl:variable name="BitString">
  479.                     <xsl:if test="($BitValue mod 2)    >= 1">invisible,</xsl:if>
  480.                     <xsl:if test="($BitValue mod 4) >= 2">hidden,</xsl:if>
  481.                     <xsl:if test="($BitValue mod 8) >= 4">print,</xsl:if>
  482.                     <xsl:if test="($BitValue mod 16) >= 8">nozoom,</xsl:if>
  483.                     <xsl:if test="($BitValue mod 32) >= 16">norotate,</xsl:if>
  484.                     <xsl:if test="($BitValue mod 64) >= 32">noview,</xsl:if>
  485.                     <xsl:if test="($BitValue mod 128) >= 64">readonly,</xsl:if>
  486.                     <xsl:if test="($BitValue mod 256) >= 128">locked,</xsl:if>
  487.                     <xsl:if test="($BitValue mod 512) >= 256">togglenoview,</xsl:if>
  488.                 </xsl:variable>
  489.                 <!-- trim off last comma -->
  490.                 <xsl:attribute name="flags">
  491.                     <xsl:value-of select="substring($BitString, 1, string-length($BitString) - 1)"/>
  492.                 </xsl:attribute>
  493.             </xsl:when>
  494.  
  495.             <!-- Page -->
  496.             <xsl:when test="$keyvalue = 'Page'">
  497.                 <xsl:attribute name="page">
  498.                     <xsl:value-of select="@VAL"/>
  499.                 </xsl:attribute>
  500.             </xsl:when>
  501.  
  502.             <!-- sound clip specific flags -->
  503.  
  504.             <!-- Bits -->
  505.             <xsl:when test="$keyvalue = 'B'">
  506.                 <xsl:attribute name="bits">
  507.                     <xsl:value-of select="@VAL"/>
  508.                 </xsl:attribute>
  509.             </xsl:when>
  510.  
  511.             <xsl:when test="$keyvalue = 'R'">
  512.                 <xsl:attribute name="rate">
  513.                     <xsl:value-of select="@VAL"/>
  514.                 </xsl:attribute>
  515.             </xsl:when>
  516.  
  517.             <xsl:when test="$keyvalue = 'C'">
  518.                 <xsl:attribute name="channels">
  519.                     <xsl:value-of select="@VAL"/>
  520.                 </xsl:attribute>
  521.             </xsl:when>
  522.  
  523.             <!-- end of sound clip specific flags -->
  524.  
  525.             <xsl:when test="$keyvalue = 'Size'">
  526.                 <xsl:attribute name="size">
  527.                     <xsl:value-of select="@VAL"/>
  528.                 </xsl:attribute>
  529.             </xsl:when>
  530.  
  531.             <xsl:when test="$keyvalue = 'Length'">
  532.                 <xsl:attribute name="length">
  533.                     <xsl:value-of select="@VAL"/>
  534.                 </xsl:attribute>
  535.             </xsl:when>
  536.  
  537.             <!-- Mac only stream settings -->
  538.  
  539.             <xsl:when test="$keyvalue = 'Subtype'">
  540.                 <xsl:attribute name="subtype">
  541.                     <xsl:value-of select="@VAL"/>
  542.                 </xsl:attribute>
  543.             </xsl:when>
  544.  
  545.             <xsl:when test="$keyvalue = 'Creator'">
  546.                 <xsl:attribute name="creator">
  547.                     <xsl:value-of select="@VAL"/>
  548.                 </xsl:attribute>
  549.             </xsl:when>
  550.  
  551.             <!-- end of Mac only stream settings -->
  552.  
  553.             <!-- Intensity -->
  554.             <xsl:when test="$keyvalue = 'I'">
  555.                 <xsl:attribute name="intensity">
  556.                     <xsl:value-of select="@VAL"/>
  557.                 </xsl:attribute>
  558.             </xsl:when>
  559.  
  560.             <!-- Opacity (really should come through FIXED[@KEY]) -->
  561.             <xsl:when test="$keyvalue = 'CA'">
  562.                 <xsl:attribute name="opacity">
  563.                     <xsl:value-of select="@VAL"/>
  564.                 </xsl:attribute>
  565.             </xsl:when>
  566.  
  567.             <!-- Quadding -->
  568.             <xsl:when test="$keyvalue = 'Q'">
  569.                 <xsl:attribute name="justification">
  570.                     <xsl:choose>
  571.                         <xsl:when test="@VAL = 0">left</xsl:when>
  572.                         <xsl:when test="@VAL = 1">centered</xsl:when>
  573.                         <xsl:when test="@VAL = 2">right</xsl:when>
  574.                     </xsl:choose>
  575.                 </xsl:attribute>
  576.             </xsl:when>
  577.  
  578.         </xsl:choose>
  579.     </xsl:template>
  580.  
  581.     <xsl:template match="FIXED[@KEY]">
  582.         <xsl:variable name="keyvalue"><xsl:value-of select="@KEY"/></xsl:variable>
  583.         <xsl:choose>
  584.  
  585.             <!-- Rotation (really should come through INT[@KEY]) -->
  586.             <xsl:when test="$keyvalue = 'Rotate'">
  587.                 <xsl:attribute name="rotation">
  588.                     <xsl:value-of select="@VAL"/>
  589.                 </xsl:attribute>
  590.             </xsl:when>
  591.  
  592.             <!-- Intensity (really should come through INT[@KEY]) -->
  593.             <xsl:when test="$keyvalue = 'I'">
  594.                 <xsl:attribute name="intensity">
  595.                     <xsl:value-of select="@VAL"/>
  596.                 </xsl:attribute>
  597.             </xsl:when>
  598.  
  599.             <!-- Opacity -->
  600.             <xsl:when test="$keyvalue = 'CA'">
  601.                 <xsl:attribute name="opacity">
  602.                     <xsl:value-of select="@VAL"/>
  603.                 </xsl:attribute>
  604.             </xsl:when>
  605.  
  606.         </xsl:choose>
  607.     </xsl:template>
  608.  
  609.     <xsl:template match="NAME[@KEY]">
  610.         <xsl:variable name="keyvalue"><xsl:value-of select="@KEY"/></xsl:variable>
  611.         <xsl:choose>
  612.  
  613.             <!-- encoding (sound clip specific) -->
  614.             <xsl:when test="$keyvalue = 'E'">
  615.                 <xsl:attribute name="encoding">
  616.                     <xsl:value-of select="translate (@VAL, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  617.                 </xsl:attribute>
  618.             </xsl:when>
  619.  
  620.             <!-- Icon -->
  621.             <xsl:when test="$keyvalue = 'Name'">
  622.                 <xsl:attribute name="icon">
  623.                     <xsl:value-of select="@VAL"/>
  624.                 </xsl:attribute>
  625.             </xsl:when>
  626.  
  627.             <!-- Border Style -->
  628.             <xsl:when test="$keyvalue = 'S'">
  629.                 <xsl:variable name="Style" select="@VAL"/>
  630.                 <xsl:attribute name="style">
  631.                     <xsl:choose>
  632.                         <xsl:when test="$Style = 'S'">solid</xsl:when>
  633.                         <xsl:when test="$Style = 'D'">dash</xsl:when>
  634.                         <xsl:when test="$Style = 'B'">bevelled</xsl:when>
  635.                         <xsl:when test="$Style = 'I'">inset</xsl:when>
  636.                         <xsl:when test="$Style = 'U'">underline</xsl:when>
  637.                         <xsl:when test="$Style = 'C'">cloudy</xsl:when>
  638.                     </xsl:choose>
  639.                 </xsl:attribute>
  640.             </xsl:when>
  641.  
  642.             <!-- Caret Symbol -->
  643.             <xsl:when test="$keyvalue = 'Sy'">
  644.                 <xsl:attribute name="symbol">
  645.                     <xsl:choose>
  646.                         <xsl:when test="@VAL = 'None' or @VAL = ''">none</xsl:when>
  647.                         <xsl:when test="@VAL = 'P'">paragraph</xsl:when>
  648.                         <xsl:when test="@VAL = 'S'">space</xsl:when>
  649.                     </xsl:choose>
  650.                 </xsl:attribute>
  651.             </xsl:when>
  652.  
  653.             <!--    Subtype (not a direct child of DICT,
  654.                     hence not annotation type) -->
  655.             <xsl:when test="$keyvalue = 'Subtype'">
  656.                 <xsl:if test="ancestor::STREAM">
  657.                     <xsl:attribute name="mimetype">
  658.                         <xsl:value-of select="@VAL"/>
  659.                     </xsl:attribute>
  660.                 </xsl:if>
  661.             </xsl:when>
  662.  
  663.         </xsl:choose>
  664.     </xsl:template>
  665.  
  666.     <xsl:template match="DICT[not(@*)]">
  667.         <!--     a DICT element without attributes is part of
  668.                 field definitions -->
  669.         <xsl:apply-templates select="STRING[@KEY = 'T']" mode="fields"/>
  670.     </xsl:template>
  671.  
  672.     <xsl:template match="DICT[@DEFINE or @KEY]">
  673.         <xsl:choose>
  674.             <xsl:when test="@KEY = 'FDF'">
  675.                 <xsl:element name="xfdf">
  676.                     <xsl:attribute name="xml:space">preserve</xsl:attribute>
  677.                     <xsl:apply-templates/>
  678.                 </xsl:element>
  679.             </xsl:when>
  680.  
  681.             <xsl:when test="@KEY='BS'">
  682.                 <xsl:if test="(FIXED|INT)[@KEY='W']">
  683.                     <xsl:attribute name="width">
  684.                         <xsl:value-of select="(FIXED|INT)[@KEY='W']/@VAL"/>
  685.                     </xsl:attribute>
  686.                 </xsl:if>
  687.                 <!-- now handle dashes and style -->
  688.                 <xsl:apply-templates/>
  689.             </xsl:when>
  690.  
  691.             <!-- this blocks processing of MacIntosh resource forks
  692.                  until after the main data stream has been processed -->
  693.             <xsl:when test="@KEY='Mac'"/>
  694.  
  695.             <xsl:when test="@KEY='FS' or @KEY='EF' or @KEY='BE'">
  696.                 <xsl:apply-templates/>
  697.             </xsl:when>
  698.             
  699.             <!--    put this case here to allow only elements
  700.                     with DEFINE attribute beyond this point -->
  701.             <xsl:when test="not(@DEFINE)">
  702.                 <xsl:apply-templates/>
  703.             </xsl:when>
  704.  
  705.             <xsl:when test="@DEFINE = '1/0'">
  706.                 <xsl:apply-templates/>
  707.             </xsl:when>
  708.  
  709.             <xsl:otherwise>
  710.                 <xsl:choose>
  711.                     <!--    most times when DICT[@DEFINE] is encountered
  712.                             this indicates a valid annotation, but
  713.                             not always -->
  714.                     <xsl:when test="NAME[@KEY = 'Subtype']">
  715.                         <!-- annotation type -->
  716.                         <!--    convert mixed cased annotation name to a lower cased
  717.                                 element name -->
  718.                         <xsl:variable name="AnnotType">
  719.                             <xsl:value-of select="translate (NAME[@KEY = 'Subtype']/@VAL, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  720.                         </xsl:variable>
  721.                         <xsl:element name="{$AnnotType}">
  722.                             <!--    make sure that embedded annotations
  723.                                     get processed last, so
  724.                                     that attributes can be added to
  725.                                     current annotation -->
  726.                             <!--    contents, richtext and
  727.                                     defaultappearance contents should
  728.                                     be processed before handling
  729.                                     embedded annotations -->
  730.                             <xsl:apply-templates select="(*[not(self::STRING[@KEY='RC' or @KEY='Contents' or @KEY='DA'] or self::DICT[@DEFINE or @KEY] or self::STREAM or self::APPEARANCE)])|DICT[@KEY='BS' or @KEY='BE']"/>
  731.                             <xsl:apply-templates select="DICT[@KEY='EF' or @KEY='FS']|STREAM|APPEARANCE"/>
  732.                             <!--    if both RC and Contents are there
  733.                                     only use RC -->
  734.                             <xsl:choose>
  735.                                 <xsl:when test="STRING[@KEY='Contents'] and STRING[@KEY='RC']">
  736.                                     <xsl:apply-templates select="STRING[@KEY='RC']"/>
  737.                                 </xsl:when>
  738.                                 <xsl:otherwise>
  739.                                     <xsl:apply-templates select="STRING[@KEY='Contents' or @KEY='RC']"/>
  740.                                 </xsl:otherwise>
  741.                             </xsl:choose>
  742.                             <xsl:apply-templates select="STRING[@KEY='DA']"/>
  743.                             <xsl:apply-templates select="DICT[@DEFINE][not(@KEY='BS' or @KEY='BE' or @KEY='FS' or @KEY='EF')]"/>
  744.                         </xsl:element>
  745.                     </xsl:when>
  746.                 </xsl:choose>
  747.             </xsl:otherwise>
  748.         </xsl:choose>
  749.     </xsl:template>
  750.  
  751.     <xsl:template match="STREAM">
  752.         <!-- do the main part -->
  753.         <xsl:apply-templates select="DATA"/>
  754.         <!-- do the resource fork, if it exists -->
  755.         <xsl:apply-templates select="DICT[@KEY='Params']/DICT[@KEY='Mac']/STREAM[@KEY='ResFork']/DATA"/>
  756.     </xsl:template>
  757.  
  758.     <xsl:template match="DATA">
  759.         <xsl:call-template name="emitParams"/>
  760.         <xsl:variable name="NodeName">
  761.         <xsl:choose>
  762.             <xsl:when test="ancestor::DICT[@KEY='Mac']">resource</xsl:when>
  763.             <xsl:otherwise>data</xsl:otherwise>
  764.         </xsl:choose>
  765.         </xsl:variable>
  766.         <xsl:element name="{$NodeName}">
  767.             <xsl:attribute name="mode">
  768.                 <xsl:value-of select="translate (@MODE, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  769.             </xsl:attribute>
  770.             <xsl:attribute name="encoding">
  771.                 <xsl:value-of select="translate (@ENCODING, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')"/>
  772.             </xsl:attribute>
  773.             <xsl:call-template name="emitRestofParams"/>
  774.             <xsl:value-of select="."/>
  775.         </xsl:element>
  776.     </xsl:template>
  777.  
  778.     <!-- get rid of any extraneous text nodes and attributes -->
  779.     <xsl:template match="text()|@*"/>
  780.  
  781. </xsl:stylesheet>
  782.